﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace GVCSMTemplates
{
    public class CalculateTableInformationTwoFrames
    {

        public DataTable tableRowsForTwoScreenWith1SessionQ1(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            if (dt.Rows.Count == 1)
            {
                object[] iRow = dt.Rows[0].ItemArray;
                resultTable.Rows.Add(iRow);
            }
            else if (dt.Rows.Count > 1)
            {
                object[] iRow = dt.Rows[1].ItemArray;
                resultTable.Rows.Add(iRow);
            }

            return resultTable;
        }

        public DataTable tableRowsForTwoScreenWith2SessionQ2(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            object[] iRow = dt.Rows[11].ItemArray;
            resultTable.Rows.Add(iRow);
            return resultTable;
        }

        public DataTable tableRowsForTwoScreenWith1SessionQ11(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            if (dt.Rows.Count == 2)
            {
                object[] iRow = dt.Rows[1].ItemArray;
                resultTable.Rows.Add(iRow);
            }
            else if (dt.Rows.Count > 2)
            {
                object[] iRow = dt.Rows[2].ItemArray;
                resultTable.Rows.Add(iRow);
            }

            return resultTable;
        }

        public DataTable tableRowsForTwoScreenWith2SessionQ22(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            object[] iRow = dt.Rows[12].ItemArray;
            resultTable.Rows.Add(iRow);
            return resultTable;
        }

        public DataTable retrieveTableForTwoScreenTemplateQ1(DataTable dt)
        {
            int rowCount = dt.Rows.Count;
            DataTable dtNormal = new DataTable();

            if (rowCount >= 12)
            {
                IniFile ini = new IniFile(@"c:\BOX\Signbox\played.ini");
                String value = ini.ReadValue("Two Screen Template Q1", "played");
                if (value == "played2")
                {
                    dtNormal = tableRowsForTwoScreenWith1SessionQ1(dt);
                    ini.WriteValue("Two Screen Template Q1", "played", "played1");
                }
                else
                {
                    dtNormal = tableRowsForTwoScreenWith2SessionQ2(dt);
                    ini.WriteValue("Two Screen Template Q1", "played", "played2");
                }
            }
            else
            {
                dtNormal = tableRowsForTwoScreenWith1SessionQ1(dt);
            }

            return dtNormal;
        }

        public DataTable retrieveTableForTwoScreenTemplateQ2(DataTable dt)
        {
            int rowCount = dt.Rows.Count;
            DataTable dtNormal = new DataTable();

            if (rowCount >= 13)
            {
                IniFile ini = new IniFile(@"c:\BOX\Signbox\played.ini");
                String value = ini.ReadValue("Two Screen Template Q2", "played");
                if (value == "played2")
                {
                    dtNormal = tableRowsForTwoScreenWith1SessionQ11(dt);
                    ini.WriteValue("Two Screen Template Q2", "played", "played1");
                }
                else
                {
                    dtNormal = tableRowsForTwoScreenWith2SessionQ22(dt);
                    ini.WriteValue("Two Screen Template Q2", "played", "played2");
                }
            }
            else
            {
                dtNormal = tableRowsForTwoScreenWith1SessionQ11(dt);
            }

            return dtNormal;
        }

    }
}